package com.xinqi.modules.databank.v2.controller.common.inner;

import com.xinqi.common.base.response.R;
import com.xinqi.modules.databank.dto.req.CourseResourceUpdateDTO;
import com.xinqi.modules.databank.dto.rsp.CourseInteractionSubmitResult;
import com.xinqi.modules.databank.dto.rsp.CourseResourceBaseResultDTO;
import com.xinqi.modules.databank.v2.service.common.CourseResourceBaseService;
import com.xinqi.modules.databank.v1.manager.CourseInteractionSubmitManager;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资料库WEB公共接口
 *
 * @author: dzy
 * @date: 2023/07/14
 */
@Tag(name = "资料库Client公共接口", description = "资料库Client公共接口")
@RestController
@RequestMapping("/inner/base/resource")
@RequiredArgsConstructor
@Validated
public class ResourceBaseInnerController {

    private final CourseResourceBaseService courseResourceBaseService;

    private final CourseInteractionSubmitManager courseInteractionSubmitService;

    /**
     * 老师端查询发布资料库
     *
     * @Author dzy
     * @Date 15:02 2023/3/16
     * @Return
     * @Exception
     */
    @GetMapping("/getInfo/{contentId}")
    public R<CourseResourceBaseResultDTO> getInfo(@PathVariable("contentId") Long contentId) {
        CourseResourceBaseResultDTO result = courseResourceBaseService.findById(contentId);
        return R.data(result);
    }

    /**
     * 修改发布资料库
     *
     * @Author dzy
     * @Date 15:02 2023/3/16
     * @Return
     * @Exception
     */
    @PutMapping("/update/{contentId}")
    public R<Boolean> update(@PathVariable("contentId") Long contentId, @RequestBody CourseResourceUpdateDTO dto) {
        dto.setId(contentId);
        return R.data(courseResourceBaseService.update(dto));
    }

    /**
     * 加入班级
     *
     * @Author dzy
     * @Date 15:02 2023/3/16
     * @Return
     * @Exception
     */
    @PutMapping("/joinClass/{classId}/{studentId}")
    public R<Boolean> joinClass(@PathVariable("classId") Long classId, @PathVariable("studentId") Long studentId) {
        return R.data(courseResourceBaseService.joinClassSyncResource(classId, studentId));
    }


    /**
     * 查询互动课件,互动视频答题提交记录
     * @Author dzy
     * @Date 15:02 2023/3/16
     * @Return
     * @Exception
     */
    @GetMapping("/find-list/{contentId}")
    public R<List<CourseInteractionSubmitResult>> findListByContentId(@PathVariable("contentId") Long contentId) {
        List<CourseInteractionSubmitResult> resultList = courseInteractionSubmitService.findListByContentId(contentId);
        return R.data(resultList);
    }

}
